package com.hengtuo.util;



import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.hengtuo.kaiyuanzhongguo.R;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

public class ImageLoderUtils {


	public void getRoundImage(String path, ImageView imageView) {
		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.showImageForEmptyUri(R.mipmap.widget_dface)
				.showImageOnFail(R.mipmap.widget_dface)
				.showImageOnLoading(R.mipmap.widget_dface)
				.displayer(new RoundedBitmapDisplayer(90)).cacheInMemory(true)
				.cacheOnDisk(true).delayBeforeLoading(1000).build();
		ImageLoader.getInstance().displayImage(path, imageView, options);
	}


	public static void getImageLoaderConfiger(Context context){
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.memoryCacheExtraOptions(480, 800)//即保存的每个缓存文件的最大长宽
				.threadPoolSize(3)// 线程池内加载的数量
				.threadPriority(Thread.NORM_PRIORITY-2)
				.denyCacheImageMultipleSizesInMemory()
				.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))//你可以通过自己的内存缓存实现
				.memoryCacheSize(2 * 1024 * 1024)
				.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000))
				.writeDebugLogs() // Remove for release app
				.build();
		ImageLoader.getInstance().init(config);
	}

	public static void getImageLoderInit(Context context){
		//初始化设置
		@SuppressWarnings("deprecation")
		ImageLoaderConfiguration config=new ImageLoaderConfiguration.Builder(context)
				.threadPriority(Thread.NORM_PRIORITY-2).writeDebugLogs()
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.build();
		ImageLoader.getInstance().init(config);//初始化
	}

	public static DisplayImageOptions getDisplayImageOptions(Context context){
		@SuppressWarnings("deprecation")
		DisplayImageOptions options=new DisplayImageOptions.Builder()
				.cacheOnDisc(true)//
				.cacheInMemory(true)//内存缓存
				//.cacheOnDisk(true)设置下载的图片是否缓存在SD卡中
				.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
				.showImageOnLoading(R.mipmap.widget_dface)
				.bitmapConfig(Bitmap.Config.RGB_565)
				.displayer(new RoundedBitmapDisplayer(50))
				.build();
		return options;

	}
}
